package com.day0916.task;

import java.util.Arrays;

public class DishManager {
    //数据
    Dish[] dishes = new Dish[3];

    //初始化菜品信息
    public void initDish(){
        Dish dish1 = new Dish();
        dish1.dishName = "红烧带鱼";
        dish1.dishPrice = 25;
        dish1.dishNo = 1;
        dish1.dishFabulous = 0;
        dishes[0] = dish1;

        Dish dish2 = new Dish();
        dish2.dishName = "香菇炖鸡";
        dish2.dishPrice = 20;
        dish2.dishNo = 2;
        dish2.dishFabulous = 0;
        dishes[1] = dish2;

        Dish dish3 = new Dish();
        dish3.dishName = "鱼香肉丝";
        dish3.dishPrice = 18.6;
        dish3.dishNo = 3;
        dish3.dishFabulous = 0;
        dishes[2] = dish3;
    }

    //显示所有菜品信息
    public void showDish(){
        System.out.println("序号\t菜名\t\t单价\t点赞数");
        for (int i = 0; i < dishes.length; i ++){
            Dish dish = dishes[i];
            dish.show();
        }
    }

    //   5   我要点赞
    public void giveTheThumbsUps(int fab_num){
        for(int i = 0; i < dishes.length; i ++){
            if (dishes[i].dishNo == fab_num){
                dishes[i].dishFabulous += 1;
                break;
            }
        }
    }

    //    6   添加菜品
    public void addDish(String dishName,double dishPrice){
        dishes = Arrays.copyOf(dishes, dishes.length+1);
        Dish dish = new Dish();
        dish.dishNo = dishes[dishes.length-2].dishNo + 1;
        dish.dishName = dishName;
        dish.dishPrice = dishPrice;
        dishes[dishes.length - 1] = dish;
    }

    //   7   修改价格
    public void revisePrice(int no,double price){
        for (int i = 0;i < dishes.length; i ++){
            if(no == dishes[i].dishNo){
                dishes[i].dishPrice = price;
                System.out.println("修改成功！");
                break;
            }
        }
    }

    //  8  删除菜品
    public void delDish(int no){
            for (int i = no-1; i < dishes.length - 1; i ++){
                dishes[i] = dishes[i + 1];
                dishes[i].dishNo = i+1;


            }
            dishes = Arrays.copyOf(dishes,dishes.length - 1);
    }


}
